﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
namespace INTEX.DataBase.Tools
{
    public partial class INTEXDBC
    {
        public void SaveICC_ABPOS_MCO(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryICC_ABPOS_MCO(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapICC_ABPOS_MCO(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertICC_ABPOS_MCO(dwLocal, 1, ITXDBVERSION);
            }
            UpdateICC_ABPOS_MCO(dwLocal);
        }
        public void MapICC_ABPOS_MCO(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public DataSet QueryICC_ABPOS_MCO(DataRow dwData, int option = 1)
        {
            DataSet setReturn = new DataSet();
            DataSet Result = new DataSet();
            DataTable tbLocal = null;
            OracleCommand or1 = OracleDB.CreateCommand();
            // APZMANDANT  APZART APZVAR APZANRKRS APZALFDNR APZSTUFE
            string ART = "";
            switch (option)
            {
                case 1:
                    or1.CommandText = "SELECT * FROM ICC_ABPOS_MCO  WHERE ABCOID=: ABCOID";
                    or1.Parameters.Add("ABCOID", OracleType.NVarChar).Value = dwData["ABCOID"].ToString();
                    break;
                case 2:
                    ART = dwData["ART"].ToString().Trim();
                    string sections = dwData["ARTDES"].ToString().Trim();
                    if (sections == "''")
                    {
                        sections = "NOT IN ('   ')";
                    }
                    else
                    {
                        sections = "IN (" + sections + ") ";
                    }
                    or1.CommandText = "SELECT * FROM ICC_ABPOS_MCO "
                        + " WHERE ART LIKE '%" + ART + "%' AND SECTION " + sections
                        + " ORDER BY KRS,LFD ";
                    /*
                    + "  ABFMANDANT=:ABFMANDANT AND ABFAUFKRS=:ABFAUFKRS AND ABFAUFLFD=:ABFAUFLFD AND ABFAUFPOS=:ABFAUFPOS";
                    or1.Parameters.Add("ABFMANDANT", OracleType.NVarChar).Value = dwData["ABFMANDANT"].ToString();
                    or1.Parameters.Add("ABFAUFKRS", OracleType.NVarChar).Value = dwData["ABFAUFKRS"].ToString();
                    or1.Parameters.Add("ABFAUFLFD", OracleType.NVarChar).Value = dwData["ABFAUFLFD"].ToString();
                    or1.Parameters.Add("ABFAUFPOS", OracleType.NVarChar).Value = dwData["ABFAUFPOS"].ToString();*/
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
            {
                tbLocal = Result.Tables[0];
                tbLocal.TableName = "ICC_ABPOS_MCO";
            }
            setReturn.Merge(Result);
            return setReturn;
        }
        public void InsertICC_ABPOS_MCO(DataRow dwData, int option = 1, string ITXDBVERSION = "50.24")
        {
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "INSERT INTO ICC_ABPOS_MCO(ABCOID, MANDANT,KRS, LFD, POS, ART, VAR, FARBE, END, ENDDATE, APPDATE, QTY, QTYP, DQTY, MPRICE, PRODV, ADMINV, SNDQTY, S, M, L, XL, SP, MP, LP, XLP)"
                        + " VALUES (SEQ_ABCOID.NEXTVAL, :KRS, :LFD, '5  ', 'ART                 ', 'VAR', 'FARB      ', 'Y', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)";
                    or1.Parameters.Add("MANDANT", OracleType.NVarChar).Value = dwData["MANDANT"];
                    or1.Parameters.Add("KRS", OracleType.NVarChar).Value = dwData["KRS"];
                    or1.Parameters.Add("LFD", OracleType.NVarChar).Value = dwData["LFD"];
                    break;
                case 2:
                    or1.CommandText = "INSERT INTO ICC_ABPOS_MCO(ABCOID,CONTROL,MANDANT, KRS, LFD, POS, ART, VAR, FARBE,ARTDES,CDES,END, ENDDATE, APPDATE, QTY, QTYP, DQTY,MPRICE, VMQSTDPSTD,VMQSTDPEK,VMQSTDPPLAN,VMQPLANPSTD,VMQPLANPEK,VMQPLANPPLAN,VMQACTPSTD,VMQACTPEK,VMQACTPPLAN,PRODV, ADMINV, SNDQTY, S, M, L, XL, SP, MP, LP, XLP)"
                        + " SELECT SEQ_ABCOID.NEXTVAL as ABCOID, '   ' AS CONTROL,A.* FROM (SELECT ABPMANDANT AS MANDANT,ABPAUFKRS AS KRS,ABPAUFLFD AS LFD,COUNT(*) AS POS,"
                        + " ABPART AS ART,ABPVAR AS VAR,ABPFARBE AS FARBE,MAX(FSABEZ) AS ARTDES,MAX(FSFABEZ) AS CDES,' ' AS END,MAX(ABPERLDAT) AS ENDDATE,0 AS APPDATE,0 AS QTY,0 AS DQTY,"
                        + " SUM(ABPSOLLMENGE7)*0.01 AS QTYP,0 AS MPRICE,0 AS VMQSTDPSTD,0 AS VMQSTDPEK,0 AS VMQSTDPPLAN,0 AS VMQPLANPSTD,0 AS VMQPLANPEK,0 AS VMQPLANPPLAN,0 AS VMQACTPSTD,0 AS VMQACTPEK,0 AS VMQACTPPLAN,0 AS PRODV,0 AS ADMINV,"
                        + " 0 AS SNDQTY,0 AS S,0 AS M, 0 AS L,0 AS XL,0 AS SP,0 AS MP, 0 AS LP,0 AS XLP"
                        + " FROM ABPOS P JOIN FSSTAMM M ON ABPART=FSART "
                        + " JOIN FSFARBEN ON ABPART=FSFART  AND ABPFARBE=FSFFARBE"
                        //+ " WHERE ABPERLKZ='J' AND NOT EXISTS"
                        + " WHERE  NOT EXISTS"
                        + " (SELECT 1 FROM ICC_ABPOS_MCO M WHERE M.MANDANT=P.ABPMANDANT AND M.KRS=P.ABPAUFKRS AND M.LFD=ABPAUFLFD AND M.ART=ABPART "
                        + " AND M.VAR =ABPVAR AND M.FARBE=ABPFARBE)"
                        + " GROUP BY ABPMANDANT,ABPAUFKRS,ABPAUFLFD,ABPART,ABPVAR,ABPFARBE) A";
                    break;
                case 3:
                    or1.CommandText = "INSERT INTO ICC_ABPOS_MCO(ABCOID,CONTROL,MANDANT, KRS, LFD, POS, PROGRP,ARTGRP,MATGRP,MATART,SECTION,ART, VAR, FARBE,ARTDES,CDES,END, ENDDATE, APPDATE, QTY, QTYP, DQTY,MPRICE, VMQSTDPSTD,VMQSTDPEK,VMQSTDPPLAN,VMQPLANPSTD,VMQPLANPEK,VMQPLANPPLAN,VMQACTPSTD,VMQACTPEK,VMQACTPPLAN,PRODV, ADMINV, SNDQTY, S, M, L, XL, SP, MP, LP, XLP)"
                        + " SELECT SEQ_ABCOID.NEXTVAL as ABCOID, '   ' AS CONTROL,A.* FROM (SELECT ABPMANDANT AS MANDANT,ABPAUFKRS AS KRS,ABPAUFLFD AS LFD,COUNT(*) AS POS,"
                        + " MAX(FSPROGRP) AS PROGRP, MAX(FSARTGRP) AS ARTGRP, MAX(FSMATGRP) AS MATGRP,MAX(FSMATART) AS MATART,MAX(FSARTPRGR) AS SECTION,ABPART AS ART,ABPVAR AS VAR,ABPFARBE AS FARBE,MAX(FSABEZ) AS ARTDES,MAX(FSFABEZ) AS CDES,' ' AS END,MAX(ABPERLDAT) AS ENDDATE,0 AS APPDATE,0 AS QTY,0 AS DQTY,"
                        + " SUM(ABPSOLLMENGE7)*0.01 AS QTYP,0 AS MPRICE,0 AS VMQSTDPSTD,0 AS VMQSTDPEK,0 AS VMQSTDPPLAN,0 AS VMQPLANPSTD,0 AS VMQPLANPEK,0 AS VMQPLANPPLAN,0 AS VMQACTPSTD,0 AS VMQACTPEK,0 AS VMQACTPPLAN,0 AS PRODV,0 AS ADMINV,"
                        + " 0 AS SNDQTY,0 AS S,0 AS M, 0 AS L,0 AS XL,0 AS SP,0 AS MP, 0 AS LP,0 AS XLP"
                        + " FROM ABPOS P JOIN FSSTAMM M ON ABPART=FSART "
                        + " JOIN FSFARBEN ON ABPART=FSFART  AND ABPFARBE=FSFFARBE"
                        //+ " WHERE ABPERLKZ='J' AND NOT EXISTS"
                        + " WHERE  P.ABPAUFKRS=:ABKAUFKRS AND P.ABPAUFLFD=:ABKAUFLFD AND NOT EXISTS"
                        + " (SELECT 1 FROM ICC_ABPOS_MCO M WHERE M.MANDANT=P.ABPMANDANT AND M.KRS=P.ABPAUFKRS AND M.LFD=ABPAUFLFD AND M.ART=ABPART "
                        + " AND M.VAR =ABPVAR AND M.FARBE=ABPFARBE)"
                        + " GROUP BY ABPMANDANT,ABPAUFKRS,ABPAUFLFD,ABPART,ABPVAR,ABPFARBE) A";
                    or1.Parameters.Add("ABKAUFKRS", OracleType.NVarChar).Value = dwData["ABKAUFKRS"];
                    or1.Parameters.Add("ABKAUFLFD", OracleType.NVarChar).Value = dwData["ABKAUFLFD"];
                    break;
            }
            setResult = Connect2Proxy(or1);
        }
        public void UpdateICC_ABPOS_MCO(DataRow dwData, int option = 1, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region=======================
                    or1.CommandText = "UPDATE ICC_ABPOS_MCO SET "
                        + "MANDANT=:MANDANT,"
                        + "KRS=:KRS,"
                        + "LFD=:LFD,"
                        + "POS=:POS,"
                        + "ART=:ART,"
                        + "VAR=:VAR,"
                        + "FARBE=:FARBE,"
                        + "CDES=:CDES,"
                        + "ARTDES=:ARTDES,"
                        + "END=:END,"
                        + "ENDDATE=:ENDDATE,"
                        + "APPDATE=:APPDATE,"
                        + "QTY=:QTY,"
                        + "QTYP=:QTYP,"
                        + "DQTY=:DQTY,"
                        + "MPRICE=:MPRICE,"
                        + "VMQSTDPSTD=:VMQSTDPSTD,"
                        + "VMQSTDPEK=:VMQSTDPEK,"
                        + "VMQSTDPPLAN=:VMQSTDPPLAN,"
                        + "VMQPLANPSTD=:VMQPLANPSTD,"
                        + "VMQPLANPEK=:VMQPLANPEK,"
                        + "VMQPLANPPLAN=:VMQPLANPPLAN,"
                        + "VMQACTPSTD=:VMQACTPSTD,"
                        + "VMQACTPEK=:VMQACTPEK,"
                        + "VMQACTPPLAN=:VMQACTPPLAN,"
                        + "PRODV=:PRODV,"
                        + "ADMINV=:ADMINV,"
                        + "SNDQTY=:SNDQTY,"
                        + "S=:S,"
                        + "M=:M,"
                        + "L=:L,"
                        + "XL=:XL,"
                        + "SP=:SP,"
                        + "MP=:MP,"
                        + "LP=:LP,"
                        + "XLP=:XLP,"
                        + "CONTROL=:CONTROL,"
                        + "PROGRP=:PROGRP,"
                        + "PROGRPD=:PROGRPD,"
                        + "ARTGRP=:ARTGRP,"
                        + "ARTGRPD=:ARTGRPD,"
                        + "MATGRP=:MATGRP,"
                        + "MATGRPD=:MATGRPD,"
                        + "MATART=:MATART,"
                        + "MATARTD=:MATARTD,"
                        + "SECTION=:SECTION "
                        + " WHERE  ABCOID=:ABCOID ";
                    or1.Parameters.Add("ABCOID", OracleType.NVarChar).Value = dwData["ABCOID"].ToString();
                    or1.Parameters.Add("MANDANT", OracleType.NVarChar).Value = dwData["MANDANT"].ToString();
                    or1.Parameters.Add("KRS", OracleType.NVarChar).Value = dwData["KRS"].ToString();
                    or1.Parameters.Add("LFD", OracleType.NVarChar).Value = dwData["LFD"].ToString();
                    or1.Parameters.Add("POS", OracleType.NVarChar).Value = dwData["POS"].ToString();
                    or1.Parameters.Add("ART", OracleType.NVarChar).Value = dwData["ART"].ToString();
                    or1.Parameters.Add("VAR", OracleType.NVarChar).Value = dwData["VAR"].ToString();
                    or1.Parameters.Add("FARBE", OracleType.NVarChar).Value = dwData["FARBE"].ToString();
                    or1.Parameters.Add("CDES", OracleType.NVarChar).Value = dwData["CDES"].ToString();
                    or1.Parameters.Add("ARTDES", OracleType.NVarChar).Value = dwData["ARTDES"].ToString();
                    or1.Parameters.Add("END", OracleType.NVarChar).Value = dwData["END"].ToString();
                    or1.Parameters.Add("ENDDATE", OracleType.NVarChar).Value = dwData["ENDDATE"].ToString();
                    or1.Parameters.Add("APPDATE", OracleType.NVarChar).Value = dwData["APPDATE"].ToString();
                    or1.Parameters.Add("QTY", OracleType.NVarChar).Value = dwData["QTY"].ToString();
                    or1.Parameters.Add("QTYP", OracleType.NVarChar).Value = dwData["QTYP"].ToString();
                    or1.Parameters.Add("DQTY", OracleType.NVarChar).Value = dwData["DQTY"].ToString();
                    or1.Parameters.Add("MPRICE", OracleType.NVarChar).Value = dwData["MPRICE"].ToString();
                    or1.Parameters.Add("VMQSTDPSTD", OracleType.NVarChar).Value = dwData["VMQSTDPSTD"].ToString();
                    or1.Parameters.Add("VMQSTDPEK", OracleType.NVarChar).Value = dwData["VMQSTDPEK"].ToString();
                    or1.Parameters.Add("VMQSTDPPLAN", OracleType.NVarChar).Value = dwData["VMQSTDPPLAN"].ToString();
                    or1.Parameters.Add("VMQPLANPSTD", OracleType.NVarChar).Value = dwData["VMQPLANPSTD"].ToString();
                    or1.Parameters.Add("VMQPLANPEK", OracleType.NVarChar).Value = dwData["VMQPLANPEK"].ToString();
                    or1.Parameters.Add("VMQPLANPPLAN", OracleType.NVarChar).Value = dwData["VMQPLANPPLAN"].ToString();
                    or1.Parameters.Add("VMQACTPSTD", OracleType.NVarChar).Value = dwData["VMQACTPSTD"].ToString();
                    or1.Parameters.Add("VMQACTPEK", OracleType.NVarChar).Value = dwData["VMQACTPEK"].ToString();
                    or1.Parameters.Add("VMQACTPPLAN", OracleType.NVarChar).Value = dwData["VMQACTPPLAN"].ToString();
                    or1.Parameters.Add("PRODV", OracleType.NVarChar).Value = dwData["PRODV"].ToString();
                    or1.Parameters.Add("ADMINV", OracleType.NVarChar).Value = dwData["ADMINV"].ToString();
                    or1.Parameters.Add("SNDQTY", OracleType.NVarChar).Value = dwData["SNDQTY"].ToString();
                    or1.Parameters.Add("S", OracleType.NVarChar).Value = dwData["S"].ToString();
                    or1.Parameters.Add("M", OracleType.NVarChar).Value = dwData["M"].ToString();
                    or1.Parameters.Add("L", OracleType.NVarChar).Value = dwData["L"].ToString();
                    or1.Parameters.Add("XL", OracleType.NVarChar).Value = dwData["XL"].ToString();
                    or1.Parameters.Add("SP", OracleType.NVarChar).Value = dwData["SP"].ToString();
                    or1.Parameters.Add("MP", OracleType.NVarChar).Value = dwData["MP"].ToString();
                    or1.Parameters.Add("LP", OracleType.NVarChar).Value = dwData["LP"].ToString();
                    or1.Parameters.Add("XLP", OracleType.NVarChar).Value = dwData["XLP"].ToString();
                    or1.Parameters.Add("CONTROL", OracleType.NVarChar).Value = dwData["CONTROL"].ToString();
                    or1.Parameters.Add("PROGRP", OracleType.NVarChar).Value = dwData["PROGRP"].ToString();
                    or1.Parameters.Add("PROGRPD", OracleType.NVarChar).Value = dwData["PROGRPD"].ToString();
                    or1.Parameters.Add("ARTGRP", OracleType.NVarChar).Value = dwData["ARTGRP"].ToString();
                    or1.Parameters.Add("ARTGRPD", OracleType.NVarChar).Value = dwData["ARTGRPD"].ToString();
                    or1.Parameters.Add("MATGRP", OracleType.NVarChar).Value = dwData["MATGRP"].ToString();
                    or1.Parameters.Add("MATGRPD", OracleType.NVarChar).Value = dwData["MATGRPD"].ToString();
                    or1.Parameters.Add("MATART", OracleType.NVarChar).Value = dwData["MATART"].ToString();
                    or1.Parameters.Add("MATARTD", OracleType.NVarChar).Value = dwData["MATARTD"].ToString();
                    or1.Parameters.Add("SECTION", OracleType.NVarChar).Value = dwData["SECTION"].ToString();
                    #endregion
                    break;
                #region===========cost=======
                case 2:
                    or1.CommandText = "UPDATE ICC_ABPOS_MCO M SET (SP,S)=(SELECT ABPSOLLMENGE7*0.01,ABPEALFM*0.01 FROM ABPOS P"
                        + " WHERE M.KRS=P.ABPAUFKRS AND M.LFD=P.ABPAUFLFD AND M.ART=P.ABPART AND M.VAR=P.ABPVAR AND M.FARBE=P.ABPFARBE AND P.ABPGROE='S      ')"
                        + " WHERE   M.MANDANT=:MANDANT AND M.KRS=:KRS AND M.LFD=:LFD  AND ART=:ART "
                        + " AND EXISTS (SELECT 1 FROM ABPOS P WHERE  M.KRS=P.ABPAUFKRS AND M.LFD=P.ABPAUFLFD AND M.ART=P.ABPART AND M.FARBE=P.ABPFARBE  AND P.ABPGROE='S      ' )";
                    or1.Parameters.Add("MANDANT", OracleType.NVarChar).Value = dwData["MANDANT"];
                    or1.Parameters.Add("KRS", OracleType.NVarChar).Value = dwData["KRS"];
                    or1.Parameters.Add("LFD", OracleType.NVarChar).Value = dwData["LFD"];
                    or1.Parameters.Add("ART", OracleType.NVarChar).Value = dwData["ART"];
                    //or1.Parameters.Add("VAR", OracleType.NVarChar).Value = dwData["VAR"];
                    //or1.Parameters.Add("FARBE", OracleType.NVarChar).Value = dwData["FARBE"];
                    break;
                case 3:
                    or1.CommandText = "UPDATE ICC_ABPOS_MCO M SET (MP,M)=(SELECT ABPSOLLMENGE7*0.01,ABPEALFM*0.01 FROM ABPOS P"
                  + " WHERE M.KRS=P.ABPAUFKRS AND M.LFD=P.ABPAUFLFD AND M.ART=P.ABPART AND M.VAR=P.ABPVAR AND M.FARBE=P.ABPFARBE AND P.ABPGROE='M      ')"
                  + " WHERE     M.MANDANT=:MANDANT AND M.KRS=:KRS AND M.LFD=:LFD  AND ART=:ART "
                  + " AND EXISTS (SELECT 1 FROM ABPOS P WHERE  M.KRS=P.ABPAUFKRS AND M.LFD=P.ABPAUFLFD AND M.ART=P.ABPART AND M.FARBE=P.ABPFARBE AND P.ABPGROE='M      ' )";
                    or1.Parameters.Add("MANDANT", OracleType.NVarChar).Value = dwData["MANDANT"];
                    or1.Parameters.Add("KRS", OracleType.NVarChar).Value = dwData["KRS"];
                    or1.Parameters.Add("LFD", OracleType.NVarChar).Value = dwData["LFD"];
                    or1.Parameters.Add("ART", OracleType.NVarChar).Value = dwData["ART"];
                    //or1.Parameters.Add("VAR", OracleType.NVarChar).Value = dwData["VAR"];
                    //or1.Parameters.Add("FARBE", OracleType.NVarChar).Value = dwData["FARBE"];
                    break;
                case 4:
                    or1.CommandText = "UPDATE ICC_ABPOS_MCO M SET (LP,L)=(SELECT ABPSOLLMENGE7*0.01,ABPEALFM*0.01 FROM ABPOS P"
                     + " WHERE M.KRS=P.ABPAUFKRS AND M.LFD=P.ABPAUFLFD AND M.ART=P.ABPART AND M.VAR=P.ABPVAR AND M.FARBE=P.ABPFARBE AND P.ABPGROE='L      ')"
                     + " WHERE   M.MANDANT=:MANDANT AND M.KRS=:KRS AND M.LFD=:LFD  AND ART=:ART "
                     + " AND EXISTS (SELECT 1 FROM ABPOS P WHERE  M.KRS=P.ABPAUFKRS AND M.LFD=P.ABPAUFLFD AND M.ART=P.ABPART AND M.FARBE=P.ABPFARBE  AND P.ABPGROE='L      ' )";
                    or1.Parameters.Add("MANDANT", OracleType.NVarChar).Value = dwData["MANDANT"];
                    or1.Parameters.Add("KRS", OracleType.NVarChar).Value = dwData["KRS"];
                    or1.Parameters.Add("LFD", OracleType.NVarChar).Value = dwData["LFD"];
                    or1.Parameters.Add("ART", OracleType.NVarChar).Value = dwData["ART"];
                    //or1.Parameters.Add("VAR", OracleType.NVarChar).Value = dwData["VAR"];
                    //or1.Parameters.Add("FARBE", OracleType.NVarChar).Value = dwData["FARBE"];
                    break;
                case 5:
                    or1.CommandText = "UPDATE ICC_ABPOS_MCO M SET (XLP,XL)=(SELECT ABPSOLLMENGE7*0.01,ABPEALFM*0.01 FROM ABPOS P"
                   + " WHERE M.KRS=P.ABPAUFKRS AND M.LFD=P.ABPAUFLFD AND M.ART=P.ABPART AND M.VAR=P.ABPVAR AND M.FARBE=P.ABPFARBE AND P.ABPGROE='XL     ')"
                   + " WHERE    M.MANDANT=:MANDANT AND M.KRS=:KRS AND M.LFD=:LFD  AND ART=:ART "
                   + " AND EXISTS (SELECT 1 FROM ABPOS P WHERE  M.KRS=P.ABPAUFKRS AND M.LFD=P.ABPAUFLFD AND M.ART=P.ABPART AND M.FARBE=P.ABPFARBE  AND P.ABPGROE='XL     ' )";
                     or1.Parameters.Add("MANDANT", OracleType.NVarChar).Value = dwData["MANDANT"];
                    or1.Parameters.Add("KRS", OracleType.NVarChar).Value = dwData["KRS"];
                    or1.Parameters.Add("LFD", OracleType.NVarChar).Value = dwData["LFD"];
                    or1.Parameters.Add("ART", OracleType.NVarChar).Value = dwData["ART"];
                    //or1.Parameters.Add("VAR", OracleType.NVarChar).Value = dwData["VAR"];
                    //or1.Parameters.Add("FARBE", OracleType.NVarChar).Value = dwData["FARBE"];
                    break;
                case 6:
                    or1.CommandText = "UPDATE ICC_ABPOS_MCO M SET QTY=S+M+L+XL,QTYP=SP+MP+LP+XLP"
                        //+" WHERE  END='J' AND M.CONTROL='   ' ";
                        //+ " WHERE  M.CONTROL='   ' AND M.KRS=P.ABPAUFKRS AND M.LFD=P.ABPAUFLFD AND M.ART=P.ABPART AND M.VAR=P.ABPVAR AND M.FARBE=P.ABPFARBE"
                    + " WHERE   M.MANDANT=:MANDANT AND  M.KRS=:KRS AND M.LFD=:LFD AND M.ART=:ART ";
                    or1.Parameters.Add("MANDANT", OracleType.NVarChar).Value = dwData["MANDANT"];
                    or1.Parameters.Add("KRS", OracleType.NVarChar).Value = dwData["KRS"];
                    or1.Parameters.Add("LFD", OracleType.NVarChar).Value = dwData["LFD"];
                    or1.Parameters.Add("ART", OracleType.NVarChar).Value = dwData["ART"];
                    //or1.Parameters.Add("VAR", OracleType.NVarChar).Value = dwData["VAR"];
                    //or1.Parameters.Add("FARBE", OracleType.NVarChar).Value = dwData["FARBE"];
                    break;
                case 7:
                    or1.CommandText = "UPDATE ICC_ABPOS_MCO M SET DQTY=QTY-QTYP"
                        //+ " WHERE  END='J' AND M.CONTROL='   ' ";
                        //+ " WHERE  M.CONTROL='   ' AND M.KRS=P.ABPAUFKRS AND M.LFD=P.ABPAUFLFD AND M.ART=P.ABPART AND M.VAR=P.ABPVAR AND M.FARBE=P.ABPFARBE"
                    + " WHERE  M.MANDANT=:MANDANT AND  M.KRS=:KRS AND M.LFD=:LFD AND M.ART=:ART ";
                    or1.Parameters.Add("MANDANT", OracleType.NVarChar).Value = dwData["MANDANT"];
                    or1.Parameters.Add("KRS", OracleType.NVarChar).Value = dwData["KRS"];
                    or1.Parameters.Add("LFD", OracleType.NVarChar).Value = dwData["LFD"];
                    or1.Parameters.Add("ART", OracleType.NVarChar).Value = dwData["ART"];
                    //or1.Parameters.Add("VAR", OracleType.NVarChar).Value = dwData["VAR"];
                    //or1.Parameters.Add("FARBE", OracleType.NVarChar).Value = dwData["FARBE"];
                    break;
                case 8:
                    or1.CommandText = "UPDATE ICC_ABPOS_MCO M SET (MPRICE,PRODV)="
                        + " (SELECT MAX(ARWERT*0.001),MAX(ARWERT*0.001*QTY) FROM ABPR P WHERE M.KRS=P.ARAUFKRS AND M.LFD=P.ARAUFLFD )"
                        + " WHERE  M.MANDANT=:MANDANT AND M.KRS=:KRS AND M.LFD=:LFD  AND ART=:ART  "
                        + " AND EXISTS (SELECT 1 FROM  ABPR P WHERE  M.KRS=P.ARAUFKRS AND M.LFD=P.ARAUFLFD )";
                    or1.Parameters.Add("MANDANT", OracleType.NVarChar).Value = dwData["MANDANT"];
                    or1.Parameters.Add("KRS", OracleType.NVarChar).Value = dwData["KRS"];
                    or1.Parameters.Add("LFD", OracleType.NVarChar).Value = dwData["LFD"];
                    or1.Parameters.Add("ART", OracleType.NVarChar).Value = dwData["ART"];
                    //or1.Parameters.Add("VAR", OracleType.NVarChar).Value = dwData["VAR"];
                    //or1.Parameters.Add("FARBE", OracleType.NVarChar).Value = dwData["FARBE"];
                    break;
                #endregion
                case 9999:
                    or1.CommandText = "UPDATE ICC_ABPOS_MCO M SET (ENDDATE,END)="
                        + " (SELECT MAX(ABPERLDAT),MIN(ABPERLKZ) FROM ABPOS P"
                        + " WHERE M.KRS=P.ABPAUFKRS AND M.LFD=P.ABPAUFLFD AND M.ART=P.ABPART AND M.VAR=P.ABPVAR AND M.FARBE=P.ABPFARBE)"
                        + " WHERE M.MANDANT=:MANDANT AND M.KRS=:KRS AND M.LFD=:LFD  AND ART=:ART AND VAR=:VAR AND FARBE=:FARBE AND EXISTS (SELECT 1 FROM ABPOS P"
                        + " WHERE  M.KRS=P.ABPAUFKRS AND M.LFD=P.ABPAUFLFD AND M.ART=P.ABPART AND M.VAR=P.ABPVAR AND M.FARBE=P.ABPFARBE )";
                    or1.Parameters.Add("MANDANT", OracleType.NVarChar).Value = dwData["MANDANT"];
                    or1.Parameters.Add("KRS", OracleType.NVarChar).Value = dwData["KRS"];
                    or1.Parameters.Add("LFD", OracleType.NVarChar).Value = dwData["LFD"];
                    or1.Parameters.Add("ART", OracleType.NVarChar).Value = dwData["ART"];
                    or1.Parameters.Add("VAR", OracleType.NVarChar).Value = dwData["VAR"];
                    or1.Parameters.Add("FARBE", OracleType.NVarChar).Value = dwData["FARBE"];
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        }
        public void DeleteICC_ABPOS_MCO(string client, string krs, string lfd, int option = 1)
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM ICC_ABPOS_MCO WHERE  "
                     + "   KRS=:KRS AND  LFD=:LFD ";
                    or1.Parameters.Add("KRS", OracleType.NVarChar).Value = krs;
                    or1.Parameters.Add("LFD", OracleType.NVarChar).Value = lfd;
                    Connect2Proxy(or1);
                    break;
                case 2:
                    break;
                default:
                    break;
            }
        }
    }
}
